#include<iostream>
using namespace std;
const int N = 1e3 + 10;
int n;
int arr[N];
int visited[N];
int parent[N];
bool Prime(int n)
{
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0) {
			return false;
		}
	}
	return true;
}

void Print()
{
	for (int i = 0; i < n - 1; i++) {
		cout << parent[i] << " ";
	}
	cout << parent[n - 1] << endl;
}
void DFS(int u, int count)
{
	count++;
	if (count == n && Prime(arr[n-1] + arr[0])) {
		parent[n - 1] = arr[u];
		Print();
	}
	visited[u] = 1;
	for (int i = 0; i < n; i++) {
		if (visited[i] == -1 && Prime(arr[u] + arr[i])) {
			parent[count - 1] = arr[u];
			DFS(i, count);
			visited[i] = -1;
		}
	}
}
int main()
{
	while (cin >> n, n) {
		for (int i = 0; i < n; i++) {
			arr[i] = i + 1;
			visited[i] = -1;
			parent[i] = -1;
		}
		int count = 0;
		DFS(0, count);
		cout << endl;
	}
	return 0;
}